/* Universidad del Valle de Guatemala
 * Mariana Castillo, 12374
 * Julio Maldonado, 12377
 * Seccion 30, Algoritmos y Estructura de Datos
 * Fecha: 03/07/13
 * DOUBLY LINKED LIST
 */

package hojat4;
public class DoublyLinkedList<E> extends AbstractList<E>{
    protected int count;
    protected DoublyLinkedNode<E> head;
    protected DoublyLinkedNode<E> tail;

    public DoublyLinkedList()
    // post: constructs an empty list
    {
       head = null;
       tail = null;
       count = 0;
    }


    public void addFirst(E value)
    // pre: value is not null
    // post: adds element to head of list
    {
       // construct a new element, making it head
       head = new DoublyLinkedNode<E>(value, head, null);
       // fix tail, if necessary
       if (tail == null) tail = head;
       count++;
    }


    public void addLast(E value)
    // pre: value is not null
    // post: adds new value to tail of list
    {
       // construct new element
       tail = new DoublyLinkedNode<E>(value, null, tail);
       // fix up head
       if (head == null) head = tail;
       count++;
    }


    public E removeLast()
    // pre: list is not empty
    // post: removes value from tail of list
    {
       DoublyLinkedNode<E> temp = tail;
       tail = tail.previous();
       if (tail == null) {
           head = null;
       } else {
           tail.setNext(null);
       }
       count--;
       return temp.value();
    }

    //Tamano de la lista
    public int size() {
        return count;
    }

    @Override
    public void clear() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    // Devuelve del elemento en la cabeza de la lista
    public E get() {
        return head.value();
    }

    @Override
    public int indexOf(E value) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    
}